package com.thread.main.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class JavaThread {

    public static void main(String[] args) throws ExecutionException, InterruptedException {


        System.out.println("线程名称:" + Thread.currentThread().getName() + ",线程ID:" + Thread.currentThread().getId());
        MyThread thread1 = new MyThread();
        thread1.start();
        System.out.println("--------------------------");
        Thread thread2 = new Thread(new MyRunnable());
        thread2.start();
        MyCallable callable = new MyCallable();
        FutureTask<Integer> future = new FutureTask<>(callable);
        Thread thread3 = new Thread(future);
        thread3.start();
        System.out.println("结果:" + future.get());

    }

    public static class MyThread extends Thread {

        @Override
        public void run() {
            System.out.println("线程名称:" + Thread.currentThread().getName() + ",线程ID:" + Thread.currentThread().getId());
            System.out.println("我是MyThread");
        }
    }

    public static class MyRunnable implements Runnable {

        @Override
        public void run() {
            System.out.println("线程名称:" + Thread.currentThread().getName() + ",线程ID:" + Thread.currentThread().getId());
            System.out.println("我是MyRunnable");
        }
    }

    public static class MyCallable implements Callable<Integer> {

        @Override
        public Integer call() throws Exception {
            System.out.println("线程名称:" + Thread.currentThread().getName() + ",线程ID:" + Thread.currentThread().getId());
            System.out.println("我是MyCallable");
            Thread.sleep(5000);
            return 1;
        }
    }
}